package com.study.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.study.mapper.LogMapper;
import com.study.model.Logs;
import com.study.model.logPOi;
import com.study.service.LogService;
import com.study.util.MyDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
;
import java.util.List;

/**
 * @author king james
 * @create 2021-09-03-{TIME}
 */
@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private LogMapper logMapper;

    @Override
    public PageInfo<Logs> selectByPage(Logs logs,int start, int length) {
        int page = start/length+1;
        //分页查询
        PageHelper.startPage(page, length);
        List<Logs> logsList = logMapper.queryAllLogInfo(logs);
        //得到日志记录
        return new PageInfo<>(logsList);
    }

    /**
     * 导出日志信息
     * @return
     */
    @Override
    public List<logPOi> exportLog() {
        return logMapper.exportLog();
    }


    /**
     * 新增日志信息
     * @param logDesc 日志信息
     * @return
     */
    @Override
    public int addLog(String logDesc) {
        //新增信息
//        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        Logs logs = new Logs();
       logs.setLogDesc(logDesc);
//        System.out.println(logDesc + "日志信息");
        MyDate myDate = new MyDate();
        logs.setCreateTime(myDate.getDate());
        return logMapper.addLog(logs);
    }

    /**
     * 删除日志
     * @param id 日志id
     * @return
     */
    @Override
    public int deleteLog(int[] ids) {
        return logMapper.deleteLog(ids);
    }
}
